import json
import tkinter as tk


with open(file='./xx.json', mode='r', encoding='utf8') as f:
    ftext = f.read()
#     print(ftext)

qdict = json.loads(ftext)

top = tk.Tk()
qL = tk.Label(top, text='')
val = tk.IntVar()
val.set(0)
a = tk.Radiobutton(top, text='', variable=val, value=1)
a.pack()
b = tk.Radiobutton(top, text='', variable=val, value=2)
b.pack()
num = 0
sc = 0

CONTINUE = True
def PrintQuestion(title, question, answers, answer):
	global num
	num += 1
	global top
	global qL
	global val
	global a
	global b
	global sc
	answerlst = answers.split(':')
	top.title(f'the {title} question')
	qL.configure(text=question)
	for i, j in ((a, 0), (b, 1)):
		i.text = answerlst[j]
	def OnOK():
		if num <=10:
			if val == answer -1:
				sc += 10
		else:
			CONTINUE = False
	tk.Button(top, text='OK', command=OnOK).pack()
	top.mainloop()

qnum = 0
while CONTINUE:
	qnum += 1
	PrintQuestion(
		qdict['title'][qnum],
		qdict['q'][qnum],
		qdict['as'][qnum],
		qdict['a'][qnum]
	)
